const path = require('path')
const { VueLoaderPlugin} = require('vue-loader')
const htmlWebpackPlugin = require('html-webpack-plugin')
const babelConfig = require('./babel.config')
const webpack = require('webpack')

module.exports = {
    mode: 'production',
    entry: './src/main.js',
    output: {
        // filename: 'bundle.js',
        filename: 'js/bundle.[contenthash:6].js',
        path: path.join(__dirname, 'dist'),
    },
    module: {
        rules: [
            {
                test: /\.vue$/,
                use: 'vue-loader',
            },
            {
                test: /\.css$/,
                use: [
                    'style-loader',
                    'css-loader'
                ]
            },
            {
                test: /\.js$/,
                use: {
                    loader: 'babel-loader',
                    options: babelConfig
                },
                exclude: /node_modules/
            },
            {
                test:  /\.js$/,
                use: 'eslint-loader',
                exclude: /node_modules/
            },
            {
                test: /\.less$/,
                use: [
                    'style-loader',
                    'css-loader',
                    'less-loader'
                ]
            },
            {
                test: /\.(png|jpe?g|git)$/,
                use: {
                    loader: 'url-loader',
                    options: {
                        name: 'img/[name].[contenthash:6].[ext]',
                        esModule: false,
                        limit: 5 * 1024
                    }
                }
            }
        ]
    },
    plugins: [
        new VueLoaderPlugin(),
        new htmlWebpackPlugin({
            title: 'zzq-webpack-demo',
            template: './public/index.html',
        }),
        // 定义全局变量
        new webpack.DefinePlugin({
            BASE_URL: '"/"' 
        })
    ]
}